/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cuadroanotacion.start;

import org.cuadroanotacionapi.beans.Jos_fastball_season;
import org.cuadroanotacionapi.controller.Jos_fastball_seasonController;
import org.cuadroanotacionapi.generales.Mensajeria;

/**
 *
 * @author avbravo
 */
public class SelectorTemporadas extends javax.swing.JInternalFrame {
 Jos_fastball_season jos_fastball_season1 = new Jos_fastball_season();
    Jos_fastball_seasonController jos_fastball_seasonContoller1 = new Jos_fastball_seasonController();
    /**
     * Creates new form SelectorTemporadas
     */
    public SelectorTemporadas() {
        initComponents();
        CargarTemporada();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jXComboBoxTemporada = new org.jdesktop.swingx.JXComboBox();
        jButtonAceptar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Seleccione la Temporada");
        setAutoscrolls(true);

        jLabel1.setText("Temporada");

        jXComboBoxTemporada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXComboBoxTemporadaActionPerformed(evt);
            }
        });

        jButtonAceptar.setText("Aceptar");
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(140, 140, 140)
                .addComponent(jButtonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXComboBoxTemporada, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 185, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jXComboBoxTemporada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addComponent(jButtonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(118, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
        try {

            Validar();
   dispose();
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "Boton");
        }
    }//GEN-LAST:event_jButtonAceptarActionPerformed

    private void jXComboBoxTemporadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXComboBoxTemporadaActionPerformed
        Validar();
    }//GEN-LAST:event_jXComboBoxTemporadaActionPerformed

    private void CargarTemporada() {
        try {
            jXComboBoxTemporada.removeAllItems();
            if (jos_fastball_seasonContoller1.Listar()) {
                for (Jos_fastball_season s : jos_fastball_seasonContoller1.getJos_fastball_seasonlist()) {
                    jXComboBoxTemporada.addItem(s.getName());
                }
                //jButtonCargar.setEnabled(true);
            } else {
                Mensajeria.Mensaje("No hay ninguna temporada activa");
                //  jButtonCargar.setEnabled(false);
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "CargarTemporada()");
        }
    }
    
   private void Validar(){
       try{
             
             int a = jXComboBoxTemporada.getSelectedIndex();
            if (a != -1) {
                jos_fastball_season1 = jos_fastball_seasonContoller1.getJos_fastball_seasonlist().get(a);
                SesionLocal.setIdtemporada( jos_fastball_season1.getId()); 
              
                
            }else{
                 SesionLocal.setIdtemporada( -1); 
            }
       } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "Validar()");
        }
   }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private org.jdesktop.swingx.JXComboBox jXComboBoxTemporada;
    // End of variables declaration//GEN-END:variables
}
